<%@ include file="/common/taglibs.jsp"%>

<head>
  <title><fmt:message key="menu.js4"/></title>
    <meta name="heading" content="<fmt:message key='menu.js4'/>"/>
    <meta name="menu" content="FormsMenu"/>

    <script src='dwr/interface/AssMarkSearch.js'></script>
    <script src='dwr/engine.js'></script>
    <script src='dwr/util.js'></script>

</head>


<div class="jquery_tab_container">
    <span class="heading_tab advanced_link active tab1"><fmt:message key="menu.js4"/></span>
</div>

<div class="jquery_tab">
    <div class="content_block"></div>
<form:form class="popupDeleteForm" commandName="assessmentsForm" method="post" action="assessmentform" id="assessmentsForm" onsubmit="return validateAssessmentsForm(this)">
    <form:errors path="*" cssClass="error" element="div"/>
    <form:hidden path="assessment.id"/>

     



            <p>
                <appfuse:label styleClass="left width150" key="basicInfo.firstName"/>
                <form:input path="assessment.workPosition.employment.firstName" id="assessment.workPosition.employment.firstName" disabled="true" style="background-color: #ccc;" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error" />
                <form:errors path="assessment.workPosition.employment.firstName" cssClass="fieldError left"/>
                  <br class="clearboth" />
                </p>

            <p>
                <appfuse:label styleClass="left width150" key="basicInfo.lastName"/>
                <form:input path="assessment.workPosition.employment.lastName" id="assessment.workPosition.employment.lastName" disabled="true" style="background-color: #ccc;"  cssClass="input-medium left toCyr" cssErrorClass="input-medium left error" />
                <form:errors path="assessment.workPosition.employment.lastName" cssClass="left fieldError"/>
                <br class="clearboth" />
            </p>

            <p>
            <appfuse:label styleClass="left width150" key="basicInfo.socScrNo"/>
            <form:input path="assessment.workPosition.employment.socScrNo" id="assessment.workPosition.employment.socScrNo" disabled="true" style="background-color: #ccc;"  cssClass="input-medium left toCyr" cssErrorClass="input-medium left error"/>
            <form:errors path="assessment.workPosition.employment.socScrNo" cssClass="left fieldError"/>
        <br class="clearboth" />
            </p>

            <p>
            <appfuse:label styleClass="left width150" key="assessment.position"/>
            <form:input path="assessment.workPosition.position" id="assessment.workPosition.position" disabled="true" style="background-color: #ccc;" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error"/>
            <form:errors path="assessment.workPosition.position" cssClass="fieldError left"/>
        <br class="clearboth" />
            </p>
            <p>
            <appfuse:label styleClass="left width150" key="searchPerson.assHalf"/>
            <form:select path="assessment.assHalf" id="assessment.assHalf"  cssClass="input-medium left toCyr">
                <form:option id="1" value="">
                    <fmt:message key='assHalfSearch'/>
                </form:option>
                <c:if test="${'1' == assessmentsForm.assessment.assHalf}"> <form:option id="2" value="1" selected="true" /> </c:if>  <c:if test="${'1' != assessmentsForm.assessment.assHalf}"> <form:option id="2" value="1" /> </c:if>
                <c:if test="${'2' == assessmentsForm.assessment.assHalf}"> <form:option id="3" value="2" selected="true" /> </c:if>  <c:if test="${'2' != assessmentsForm.assessment.assHalf}"> <form:option id="3" value="2" /> </c:if>
            </form:select>
              <br class="clearboth" />
            </p>

            <p>
            <appfuse:label styleClass="left width150" key="assessment.year"/>
            <form:input path="assessment.assYear" id="assessmentYear"  cssClass="input-medium left toCyr" cssErrorClass="input-medium left error"/>
            <form:errors path="assessment.assYear" cssClass="fieldError left"/>
            <br class="clearboth" />
            </p>

            <p>
            <appfuse:label styleClass="left width150" key="assessment.isAssessed"/>
       
           <form:select path="assessment.isAssessed" id="isAssessed"  cssClass="isAssessed input-medium left toCyr">
                
                <c:if test="${true == assessmentsForm.assessment.isAssessed}">
                    <form:option id="2" value="1" selected="true">
                        <fmt:message key="text.da" />
                    </form:option>
                </c:if>
                <c:if test="${true != assessmentsForm.assessment.isAssessed}">
                    <form:option id="2" value="1">
                        <fmt:message key="text.da" />
                    </form:option>
                </c:if>
                <c:if test="${false == assessmentsForm.assessment.isAssessed}">
                    <form:option id="3" value="0" selected="true">
                        <fmt:message key="text.ne" />
                    </form:option>
                </c:if>
                <c:if test="${false != assessmentsForm.assessment.isAssessed}">
                    <form:option id="3" value="0">
                        <fmt:message key="text.ne" />
                    </form:option>
                </c:if>
            </form:select>
                 <form:errors path="assessment.isAssessed" cssClass="fieldError left"/>
                 <br class="clearboth" />
            </p>


            <p class="assessmentNumeric">
                <appfuse:label styleClass="left width150" key="assessment.numeric"/>
                <form:input path="assessment.assessment" id="assessmentNumeric" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error"/>
                <form:errors path="assessment.assessment" cssClass="fieldError"/>
                <br class="clearboth" />
            </p>

            <p class="unassessedReasonSelect">
            <appfuse:label styleClass="left width150" key="assessment.unassessedReason"/>
            <form:select path="assessment.unassReason.id" id="unassessedReasonSelect">
                <form:option id="1" value="-1">
                    <fmt:message key='unassReasonSearch'/>
                </form:option>
                <c:forEach items="${assessmentsForm.unassessedReason}" var="reason">

                    <c:if test="${reason == assessmentsForm.assessment.unassReason}">
                        <form:option value="${reason.id}" id="${workPositionForm.assessment.unassReason.id}" selected="true">
                            ${reason.name}
                        </form:option>
                    </c:if>
                    <c:if test="${reason != assessmentsForm.assessment.unassReason }">
                        <form:option value="${reason.id}" id="${workPositionForm.assessment.unassReason.id}" >
                            ${reason.name}
                        </form:option>
                    </c:if>
                </c:forEach>
            </form:select>
           <br class="clearboth" />
            </p>

            <p class="assMarkName">
            <appfuse:label styleClass="left width150" key="assessment.assMark"/>
            <form:input disabled="true" path="assessment.assmark.name"  style="background-color: #ccc;" id="assMarkName" cssClass="input-medium left toCyr" cssErrorClass="input-medium left error"/>
            <form:hidden path="assessment.assmark.id" id="assMarkId" />
             <br class="clearboth" />
            </p>
            <script>
                
                var names = new Array();
                var maxs  = new Array();
                var mins  = new Array();
                var ids  = new Array();

                    <c:forEach items="${assessmentsForm.assessmentMark}" var="mark" varStatus="x">
                names[${x.index}] = "${mark.name}";
                mins[${x.index}] = ${mark.numAssMarkFrom};
                maxs[${x.index}] = ${mark.numAssMarkTo};
                ids[${x.index}] = "${mark.id}";

                </c:forEach>
               
               
                jQuery("#assessmentNumeric").blur(function () {
                    var elem = jQuery(this);
                    if (elem.val() < 0 || elem.val() > maxs[maxs.length-1]) {
                        alert("Mora da se vnese vrednost pomegju "+mins[0]+" i "+maxs[maxs.length-1]);
                        elem.val("");
                    }
            
                    for (var i = 0; i < names.length; i++) {
                    
                        if(mins[i] < elem.val() && elem.val() <= maxs[i]) {
                            jQuery("#assMarkName").val(names[i]);
                            jQuery("#assMarkId").attr("value", ids[i]);
                        }
                    }
                
                });
            </script>

        <form:hidden id="reasonDelete" path="savedReason.id"/>
        <p class="buttonBar bottom">
            <input type="submit" onclick="return assessControl();" class="button" name="save" value="<fmt:message key="button.save"/>" />
            <c:if test="${not empty assessmentsForm.assessment.id}">
                 <input type="button" class="button" onclick="confirmDelete();"
            value="<fmt:message key="button.delete"/>" />
            </c:if>
            <%--<input type="submit" class="button" name="cancel" value="<fmt:message key="button.cancel"/>" onclick="bCancel=true"/>--%>
            <input
                type="submit"
                class="button"
                name="cancel"
                value="<fmt:message key="button.cancel"/>"
                 onclick="location.href='<c:url value="/searchAssessments"/>'"

             />
        </p>

</form:form>

</div>

<div id="confirmdelete">
    <fmt:message key="delete.reasonDescription" />
    <select id="deleteReasonId">
        <c:forEach items="${assessmentsForm.deleteReason}" var="reason">
             <option value="${reason.id}">
                ${reason.name}
             </option>
        </c:forEach>
    </select>
</div>


<v:javascript formName="assessmentsForm" cdata="false" dynamicJavascript="true" staticJavascript="false"/>
<script type="text/javascript" src="<c:url value='/scripts/validator.jsp'/>"></script>
<script type="text/javascript">
    Form.focusFirstElement($('assessmentsForm'));

    jQuery(".unassessedReasonSelect").hide();

    jQuery(".isAssessed").change(function () {
   
       if(jQuery(this).val()==1) {
           jQuery(".unassessedReasonSelect").hide();
           jQuery(".assessmentNumeric").show();
           jQuery(".assMarkName").show();

       }
       else {
           jQuery(".unassessedReasonSelect").show();
           jQuery(".assessmentNumeric").hide();
           jQuery(".assMarkName").hide();
       }
    });






    function assessControl() {
          
            var isAssesed = document.getElementById("isAssessed");

            var grade = document.getElementById("assessmentNumeric");

            var descr =  document.getElementById("unassessedReasonSelect");

            var ok = true;

            if (jQuery(".isAssessed").val() == 1){

                if(grade.value =='' || grade.value == null )  {
                    alert("<fmt:message key='assessment.grade'/>");
                    ok = false;
                }

            }
            else if (descr.value == -1){

                alert("<fmt:message key='assessment.unassesed'/>");
                ok = false;
            }

            return ok;
        }
</script>
